package com.anmai.crawler1.dao;

import com.anmai.crawler1.base.dao.BaseDao;
import com.anmai.crawler1.entity.AreaBean;
import org.apache.ibatis.annotations.*;

import java.awt.geom.Area;
import java.util.List;

public interface AreaDao extends BaseDao<AreaDao>{
    int deleteByPrimaryKey(Integer id);

//    @Insert("insert into area(city_id,area_name,create_time,update_time) values(#{cityId},#{areaName},#{createTime},#{updateTime})")
    int insert(AreaBean record);

    List<AreaBean> findAreas(AreaBean areaBean);

    int insertSelective(AreaBean record);

    AreaBean selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(AreaBean record);

//    @Update("update area set status = #{status,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}")
    int updateByPrimaryKey(AreaBean record);

    @Select("select count(id) from area where area_name = #{areaName,jdbcType=VARCHAR} and url = #{url,jdbcType=VARCHAR} and city_id = #{cityId,jdbcType=INTEGER}")
    Integer isExist(AreaBean areaBean);

    @Select("select * from area where status = #{status,jdbcType=INTEGER}")
    @Results({
            @Result(property = "updateTime", column = "update_time"),

            @Result(property = "createTime", column = "create_time"),

            @Result(property = "cityId", column = "city_id"),

            @Result(property = "areaName", column = "area_name")
    })
    List<AreaBean> findErrorAreas(@Param("status") Integer status);

    //更新状态
    @Update("update area set status =  #{status,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}")
    Integer updateStatus(AreaBean areaBean);

    //查找没有商圈的区域
    @Select("SELECT * from  area WHERE id not in (SELECT area_id FROM bussiness) and status <> -1")
    @Results({
            @Result(property = "updateTime", column = "update_time"),

            @Result(property = "createTime", column = "create_time"),

            @Result(property = "cityId", column = "city_id"),

            @Result(property = "areaName", column = "area_name")
    })
    List<AreaBean> findAreaNoBussiness();

}